//
//  ListNolibController.m
//  OCDemo
//
//  Created by BH on 15/10/12.
//  Copyright © 2015年 baohan. All rights reserved.
//

#import "ListNolibController.h"
#import "CommonData.h"
#import "MLExpressionManager.h"
#import "ListNolibCell.h"
#import "UIView+Convenience.h"

@interface ListNolibController ()

@property(nonatomic,strong)NSArray *expressionData;
@property(nonatomic,strong)NSMutableDictionary *cellHeights;

@end

@implementation ListNolibController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"ListNolib";

    MLExpression *exp = [MLExpression expressionWithRegex:@"\\[[a-zA-Z0-9\\u4e00-\\u9fa5]+\\]" plistName:@"Expression" bundleName:@"ClippedExpression"];
    self.expressionData = [MLExpressionManager expressionAttributedStringsWithStrings:kCommonListData() expression:exp];
    
    [self.tableView registerClass:[ListNolibCell class] forCellReuseIdentifier:@"ListNolibCell"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - getter
-(NSMutableDictionary *)cellHeights
{
    if (!_cellHeights) {
        _cellHeights = [NSMutableDictionary new];
    }
    
    return _cellHeights;
}

#pragma mark - tableview datasource & delegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ListNolibCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ListNolibCell" forIndexPath:indexPath];
    
    cell.linkLab.attributedText = self.expressionData[indexPath.row%self.expressionData.count];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height = [ListNolibCell heightForExpressionText:self.expressionData[indexPath.row%self.expressionData.count] width:self.view.frameWidth];
    
    return height;
}

@end
